<html>
<head><title>CS143 Project 1B</title></head>
<body>
Type an SQL query in the following box:
<p>
<form method="GET">
<textarea name="query" cols="60" rows="8"></textarea>
<input type="submit" value="Submit" />
</form>
</p>
<?php
if($_GET["query"]) {
  $query = $_GET["query"];
  $db_connection = mysql_connect("localhost", "cs143", "");
  mysql_select_db("CS143", $db_connection);
  $rs = mysql_query($query, $db_connection);
  
  print "<table border=1 cellspacing=1 cellpadding=2>";
  $size = mysql_num_fields($rs);
  
  print "<tr>";
  for($i = 0; $i < $size; ++$i) {
    $fieldName = mysql_field_name($rs, $i);
    print "<td><b>" .$fieldName ."</b></td>";
  }
  print "</tr>";
  
  while($row = mysql_fetch_row($rs)) {
    for($i = 0; $i < $size; ++$i) {
      if ($row[$i] == NULL)
        $row[$i] = "N/A";
      print "<td>" .$row[$i] ."</td>";
    }
    print "</tr>";
  }
  print "</table>";
  
  mysql_free_result($rs);
  mysql_close($db_connection);
}
?>


</body>
</html>
